﻿using System;
using Dpx.Models;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;

namespace Dpx.ViewModels {
    public class FilterViewModel : ViewModelBase {
        // *********** 绑定属性

        /// <summary>
        /// 条件内容。
        /// </summary>
        public string Content {
            get => _content;
            set => Set(nameof(Content), ref _content, value);
        }

        /// <summary>
        /// 条件内容。
        /// </summary>
        private string _content;

        /// <summary>
        /// 条件类型。
        /// </summary>
        public FilterType Type {
            get => _type;
            set => Set(nameof(Type), ref _type, value);
        }

        /// <summary>
        /// 条件类型。
        /// </summary>
        private FilterType _type = FilterType.NameFilter;

        /******** 绑定命令 ********/

        /// <summary>
        /// 添加命令。
        /// </summary>
        public RelayCommand AddCommand => _addCommand ??=
            new RelayCommand(AddCommandFunction);

        /// <summary>
        /// 添加命令。
        /// </summary>
        private RelayCommand _addCommand;

        public void AddCommandFunction() {
            _queryPageViewModel.AddFilterViewModel(this);

        }


        /// <summary>
        /// 删除命令。
        /// </summary>
        public RelayCommand RemoveCommand =>
            _removeCommand ??=
                new RelayCommand(RemoveCommandFunction);

        /// <summary>
        /// 删除命令。
        /// </summary>
        private RelayCommand _removeCommand;

        public void RemoveCommandFunction() {
            _queryPageViewModel.RemoveFilterViewModel(this);
        }


        // *********** 私有属性

        /// <summary>
        /// 诗词搜索页ViewModel。
        /// </summary>
        private readonly QueryPageViewModel _queryPageViewModel;

        /******** 构造函数 ********/

        /// <summary>
        /// 搜索条件ViewModel。
        /// </summary>
        /// <param name="queryPageViewModel">诗词搜索页ViewModel。</param>
        public FilterViewModel(QueryPageViewModel queryPageViewModel) {
            _queryPageViewModel = queryPageViewModel;
        }
    }
}